package com.brsya.movie.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.brsya.base.bean.InventoryDetailBean;
import com.brsya.base.recycler.BaseAdapter;
import com.brsya.base.recycler.BaseViewHolder;
import com.brsya.base.util.GlideUtil;
import com.brsya.movie.R;
import com.brsya.movie.util.AppUtil;
import com.brsya.movie.widget.ScoreView;

import java.util.Locale;

/**
 * Created by Brsya
 * CreateDate: 2022/7/6  21:08
 * Description:
 * 片单详情适配器
 */
public class InventoryDetailListAdapter extends BaseAdapter<InventoryDetailBean> {

    private final Context context;

    public InventoryDetailListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public BaseViewHolder onCreate(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(context).inflate(R.layout.item_ranking_list, parent, false);
        return new BaseViewHolder(rootView);
    }

    @Override
    public void onBind(BaseViewHolder viewHolder, int RealPosition, InventoryDetailBean data) {
        ImageView ivRankingImg = viewHolder.findViewById(R.id.iv_ranking_img);
        TextView tvRankingNum = viewHolder.findViewById(R.id.tv_ranking_num);
        TextView tvRankingName = viewHolder.findViewById(R.id.tv_ranking_name);
        ScoreView svScoreBox = viewHolder.findViewById(R.id.sv_score_box);
        TextView tvRankingInfo = viewHolder.findViewById(R.id.tv_ranking_info);
        TextView tvRankingPerformer = viewHolder.findViewById(R.id.tv_ranking_performer);
        LinearLayout llRankingTagBox = viewHolder.findViewById(R.id.ll_ranking_tag_box);
        if (data == null) {
            return;
        }

        GlideUtil.loadRound(ivRankingImg, data.getCoverUrl(), 6);
        tvRankingNum.setVisibility(View.GONE);
        tvRankingName.setText(data.getName());
        svScoreBox.setScore(data.getDoubanScore());
        tvRankingInfo.setText(String.format(Locale.getDefault(), "%1s/%2s", data.getVideoYear(), data.getVideoArea()));
        tvRankingPerformer.setText(String.format(Locale.getDefault(), "主演：%1s", data.getVideoPerformer()));
        AppUtil.addTagView(context, llRankingTagBox, data.getVideoTag());
    }

}
